//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.juanran.common.module;


import com.juanran.common.enums.EnumBase;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode
@ApiModel(
        value = "RestResult",
        description = "Rest api请求结果统一封装对象"
)
public final class RestResult<T> {
    public static final String OPT_SUCCESS_STATUS = "complete";
    public static final String OPT_ERROR_STATUS = "error";
    @ApiModelProperty("api执行结果状态：成功:complete 失败: error")
    private String status;
    @ApiModelProperty("错误代码")
    private String errorCode;
    @ApiModelProperty("错误信息")
    private String errorMessage;
    @ApiModelProperty("分页查询的总记录数")
    private Long count;
    @ApiModelProperty("返回结果数据")
    private T resultData;

    public static <T> RestResult<T> success(T t) {
        return new RestResult("complete", (String)null, (String)null, 0L, t);
    }

    public static RestResult success() {
        return new RestResult("complete", (String)null, (String)null, 0L, (Object)null);
    }

    public static <T> RestResult<T> success(T t, Long count) {
        return new RestResult("complete", (String)null, (String)null, count, t);
    }

    public static <T> RestResult<T> successPage(T t, Long count) {
        return new RestResult("complete", (String)null, (String)null, count, t);
    }

    public static <T> RestResult<T> fail(String errorCode, String errorMessage) {
        return new RestResult("error", errorCode, errorMessage, 0L, (Object)null);
    }

    public static <T> RestResult<T> fail(String errorMessage) {
        return new RestResult("error", "001", errorMessage, 0L, (Object)null);
    }

    public static <T> RestResult<T> fail(EnumBase errorCode) {
        return fail(errorCode.getCode(), errorCode.getMessage());
    }

    public static <T> RestResult<T> failList(EnumBase errorCode, T t) {
        return new RestResult(errorCode.getCode(), errorCode.getMessage(), (String)null, 0L, t);
    }

    public boolean isSuccess() {
        return "complete".equals(this.status);
    }

    public String getStatus() {
        return this.status;
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public String getErrorMessage() {
        return this.errorMessage;
    }

    public Long getCount() {
        return this.count;
    }

    public T getResultData() {
        return this.resultData;
    }

    public void setStatus(final String status) {
        this.status = status;
    }

    public void setErrorCode(final String errorCode) {
        this.errorCode = errorCode;
    }

    public void setErrorMessage(final String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public void setCount(final Long count) {
        this.count = count;
    }

    public void setResultData(final T resultData) {
        this.resultData = resultData;
    }

    public String toString() {
        return "RestResult(status=" + this.getStatus() + ", errorCode=" + this.getErrorCode() + ", errorMessage=" + this.getErrorMessage() + ", count=" + this.getCount() + ", resultData=" + this.getResultData() + ")";
    }

    public RestResult() {
    }

    public RestResult(final String status, final String errorCode, final String errorMessage, final Long count, final T resultData) {
        this.status = status;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
        this.count = count;
        this.resultData = resultData;
    }
}
